package com.fieldchain.ex.fa100.ui.trade.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fieldchain.ex.fa100.R;
import com.fieldchain.ex.fa100.inter.IntegerCallBack;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/9/13
 */
public class ChoseMarketAdapter extends RecyclerView.Adapter<ChoseMarketAdapter.ViewHolder> {
    private Context mContext;

    private String tags="";
    private IntegerCallBack callBack;
    public ChoseMarketAdapter(Context mContext,IntegerCallBack callBack) {
        this.mContext = mContext;
        this.callBack=callBack;
    }
    private List<String> list = new ArrayList<>();

    public void setData(List<String> list,String tags) {
        this.list.clear();
        this.list.addAll(list);
        this.tags=tags;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_bankchaose,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        if(tags.equals(list.get(position))){
            holder.cbox.setChecked(true);
        }else{
            holder.cbox.setChecked(false);
        }
         holder.tvName.setText(list.get(position).toUpperCase());
         holder.reaItem.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
                 callBack.index(position);
             }
         });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private RelativeLayout reaItem;
        private TextView tvName;
        private CheckBox cbox;

        public ViewHolder(View itemView) {
            super(itemView);
            reaItem = itemView.findViewById(R.id.rea_item);
            tvName = itemView.findViewById(R.id.tv_name);
            cbox = itemView.findViewById(R.id.cbox);
        }
    }
}
